import {Injectable} from '@angular/core';
import {HttpService} from '../http.service';
import {adSystemApiUrl, tuikeSystemUrl} from '../../../../config/api';

@Injectable()

export class PermissionService {

  constructor(
    private httpService: HttpService
  ) {
  }

  /**
   * 权限列表
   * @param name
   * @param model
   * @param orderField
   * @param orderSort
   * @param pageSize
   * @returns {Observable<R>}
   */
  getPermissionList(page, pageSize) {
    const url = `${tuikeSystemUrl}/api/v1/admin/rbac/permission_index?page=${page}&pageSize=${pageSize}`;
    return this.httpService.httpGetAuth(url).map(data => data);
  }


  getPermissionTree() {
    const url = `${tuikeSystemUrl}/api/v1/admin/rbac/permission_tree`;
    return this.httpService.httpGetAuth(url).map(data => data);
  }


  /**
   * 权限添加
   * @param data
   * @returns {Observable<R>}
   */
  addPermission(data) {
    const url = `${tuikeSystemUrl}/api/v1/admin/rbac/permission_add`;
    return this.httpService.httpPostAuth(url, data).map(data => data);
  }

  /**
   * 权限修改
   * @param data
   * @returns {Observable<R>}
   */
  editPermission(data) {
    const url = `${tuikeSystemUrl}/api/v1/admin/rbac/permission_update`;
    return this.httpService.httpPostAuth(url, data).map(data => data);
  }

  /**
   * 权限删除
   * @param id
   * @returns {Observable<R>}
   */
  delPermission(id) {
    const url = `${tuikeSystemUrl}/api/v1/admin/rbac/permission_delete`;
    return this.httpService.httpPostAuth(url, {'id': id}).map(data => data);
  }

  /**
   * 权限信息
   * @param id
   * @returns {Observable<R>}
   */
  getPermissionInfo(id) {
    const url = `${tuikeSystemUrl}/api/v1/admin/rbac/permission_info?id=${id}`;
    return this.httpService.httpGetAuth(url).map(data => data);
  }
}
